package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 苏成博
 * @date 2023-02-12 18:43
 */
@RestController
@RequestMapping("/user/shoppingCart")
@Api(tags = "购物车模块")
@Slf4j
public class ShoppingCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;
    @PostMapping("/add")
    @ApiOperation("添加购物车")
    public Result addShoppingCart(@RequestBody ShoppingCartDTO shoppingCartDTO){
        shoppingCartService.addShoppingCart(shoppingCartDTO);
        return Result.success();
    }
    @GetMapping("/list")
    @ApiOperation("查询购物车信息")
    public Result<List<ShoppingCart>> listShoppingCart(){
        List<ShoppingCart> shoppingCartList=shoppingCartService.listShoppingCart();
        return Result.success(shoppingCartList);
    }
    @PostMapping("/sub")
    @ApiOperation("删除购物车里的一个商品")
    public Result deleteOne(@RequestBody ShoppingCartDTO shoppingCartDTO){
        shoppingCartService.deleteOne(shoppingCartDTO);
        return Result.success();
    }
    @DeleteMapping("/clean")
    @ApiOperation("清除此用户所有的购物车数据")
    public Result deleteAll(){
        shoppingCartService.deleteAll();
        return Result.success();
    }
}
